﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace test_c_sharp
{
    /// <summary>
    /// The DoodadManager handles all doodads.
    /// </summary>
    class DoodadManager
    {
        #region fields
        private List<Doodad> Doodads;
        #endregion

        #region properties
        private Rectangle bounds;
        #endregion

        #region initialization
        public DoodadManager()
        {
            Doodads = new List<Doodad>();
        }
        #endregion

        #region methods
        public void AddDoodad(Doodad newdoodad)
        {
            Doodads.Add(newdoodad);
        }
        public void RemoveDoodad(Doodad doodad)
        {
            Doodads.Remove(doodad);
        }

        public void UpdateDoodad()
        {
            KeyboardState aCurrentKeyboardState = Keyboard.GetState();
            foreach (var doodad in Doodads)
            {
                bounds = doodad.Bounds;

                if (aCurrentKeyboardState.IsKeyDown(Keys.Right) == true)
                {
                    bounds.X++;
                }

                if (aCurrentKeyboardState.IsKeyDown(Keys.Left) == true)
                {
                    bounds.X--;
                }

                if (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true)
                {
                    bounds.Y--;
                }

                if (aCurrentKeyboardState.IsKeyDown(Keys.Down) == true)
                {
                    bounds.Y++;
                }


                doodad.SetBounds(bounds);
            }
        }
        
        public void DrawDoodad(SpriteBatch spritebatch)
        {
            foreach (var doodad in Doodads)
                doodad.Draw(spritebatch);
        }
        #endregion

    }
}
